import 'package:flutter/material.dart';
import 'package:x3_charts_core/chart_painter/funnel_chart_painter.dart';
import 'package:x3_charts_core/model/funnel_chart_data_model.dart';

///**
///* @author hrongyong
///* @date   1/26/21
///* @email hrongyong@gmail.com
///* Description: 漏斗图
///*/
class FunnelChartWidget extends StatefulWidget {
  ///数据源
  final List<FunnelChartDataModel> chartModelList;

  ///是否显示副标题
  final bool isShowSubTitle;

  ///背景色
  final Color backgroundColor;

  FunnelChartWidget({@required this.chartModelList, this.backgroundColor = Colors.white, this.isShowSubTitle = true});

  @override
  _FunnelChartWidgetState createState() => _FunnelChartWidgetState();
}

class _FunnelChartWidgetState extends State<FunnelChartWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 10, right: 10, bottom: 10),
      alignment: Alignment.center,
      child: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return CustomPaint(
            size: Size(constraints.maxWidth, constraints.maxHeight),
            painter: FunnelChartPainter(
              chartModelList: widget.chartModelList,
              isShowSubTitle: widget.isShowSubTitle,
              backgroundColor: widget.backgroundColor,
            ),
          );
        },
      ),
    );
  }
}
